home *** CD-ROM | disk | FTP | other *** search
- /*
- File: OSLInit.c
-
- Contains: Initialization routines for the OSL
-
- Owned by: Nick Pilch
-
- Copyright: © 1993,4 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/15/96 TJ Cleaned Up
- <7> 7/27/95 eeh 1204615: remove Nick's DebugStr
- <6> 6/27/95 NP 1262792: new version of OSLObjectInit
- <5> 5/3/95 NP 1211084: Remove 5$
- <4> 1/12/95 jpa Don't use obsolete Toolbox names [1211211]
- <3> 9/29/94 RA 1189812: Mods for 68K build.
- <2> 8/19/94 NP 1181622: Ownership fix.
- <7> 5/2/94 eeh bug #1160654: various PPC native changes
- <6> 2/7/94 NP Tiger Team doings.
- <5> 11/5/93 NP Change in function declaration to satisfy
- MPW C.
- <4> 11/2/93 NP Move pascal keyword.
- <3> 10/11/93 NP Added DebugStr.
- <2> 7/28/93 NP Mods for new token type, OSLToken.
- <1> 7/21/93 NP first checked in
-
- To Do:
- In Progress:
- */
-
- /*
- ©Apple Computer, Inc. 1992
- All Rights Reserved.
- Author: Eric House
- */
-
- #ifndef _OSLPRIV_
- #include "OSLPriv.h"
- #endif
-
- #pragma segment AEObjSuppt
-
- //pascal OSErr
- //AEObjectInit(void);
- pascal OSErr
- iAESetObjectCallbacks( OSLCompareUPP myCompareProc, OSLCountUPP myCountProc,
- OSLDisposeTokenUPP myDisposeTokenProc,
- OSLGetMarkTokenUPP myGetMarkTokenProc, OSLMarkUPP myMarkProc,
- OSLAdjustMarksUPP myAdjustMarksProc,
- OSLGetErrDescUPP reserved );
-
- /* WARNING: this struct depends on the current implementation of the hash
- * manager staying the same. If it changes, this will break! */
-
- typedef struct {
- long someLongField ;
- long hashTableSize ;
- } hashTableRec, *hashTableRecP, **hashTableRecH ;
-
- static Boolean IsValidHashTable( HHand ahp )
- {
- long hSize ;
- Boolean retVal = false ; /* the safe thing to assume */
-
- hSize = GetHandleSize( (Handle)ahp ) ;
- if ( (MemError() == noErr)
- && (hSize == (*(hashTableRecH)ahp)->hashTableSize) )
- retVal = true ;
- return retVal;
- }
-
-
- #pragma segment AEObjGlue
- //#if GENERATINGCFM
- void ShouldNotBeHere();
- void ShouldNotBeHere()
- {
- DebugStr( "\pYou shouldn't be here" ) ;
- }
- //#endif
-
- /*Initializes the hash table and other goodies required by the object
- resolution stuff */
- pascal OSErr
- iAEObjectInit(OSLContext* context)
- {
-
- GlobalRecHandle appGlobal ;
- GlobalRecHandle sysGlobal ;
- OSErr out ;
- long ignore ;
- HHand tempH ; /* added to avoid Hlock and Unlock around AENewHashTable calls */
- OSLToken nullDesc ;
- OSErr err;
-
- err = AddContextToTopOfStack(context);
- if (err) return err;
-
- // NOTICE BOGUS PROCPTR HERE FOR NOW. ONLY HERE BECAUSE OF COMMENT BELOW,
- // "inits app global"
-
- #if GENERATINGCFM
- out = AEInstallSpecialHandler( keySelectProc,
- (UniversalProcPtr)ShouldNotBeHere, false ) ;
- #else
- // out = AEInstallSpecialHandler( keySelectProc,
- // (UniversalProcPtr)SelectorDispatch, false ) ; /* inits app global */
- out = AEInstallSpecialHandler( keySelectProc,
- (UniversalProcPtr)ShouldNotBeHere, false ) ;
- #endif
- appGlobal = GetGlobalRef();
-
- /* if it is not already inited, we must force the AEM to init the system global */
- sysGlobal = GetSysGlobal() ;
- if ( sysGlobal == NULL )
- {
- IgnoreOSErr( AEGetEventHandler( 'go b', 'ears', (AEEventHandlerUPP *)ignore,
- &ignore, true ) ) ;
- sysGlobal = GetSysGlobal() ;
- }
-
- if ( out == noErr )
- if ( ((*appGlobal)->accessorHashTable == nil)
- || !IsValidHashTable( (*appGlobal)->accessorHashTable ) )
- {
- out = AENewHashTable( kInitialHashTableSize, 8, 8, NULL, false, &tempH );
- if ( out == noErr )
- (*appGlobal)->accessorHashTable = tempH ;
- }
-
- if ( ((*sysGlobal)->accessorHashTable == nil) && (out == noErr) )
- #ifdef _MPWFIX_
- if ( ((*sysGlobal)->AccessorHashTable == nil )
- || !IsValidHashTable( (*sysGlobal)->AccessorHashTable )
- #endif
- {
- // out = AENewHashTable( kInitialHashTableSize, 8, 8, NULL, true, &tempH ) ;
- if ( out == noErr )
- (*sysGlobal)->accessorHashTable = tempH ;
- }
-
- // <eeh> removed 7/93 as part of PPC port; will call the coercion directly rather
- // than via the AEM.
- // if ( out == noErr )
- // out = AEInstallCoercionHandler( typeWhoseDescriptor, typeWhoseDescriptor,
- // (EventHandlerUPP)MakeExternalWhose, 0, true, false ) ;
-
- MakeNullToken( &nullDesc ) ; /* 3/11/92 */
- SetExmn( &nullDesc ) ;
-
- return out ;
- }
-
- #pragma segment AEObjSuppt
-
- OSErr MakeExternalWhose( const AEDesc* desc, AEDesc *result )
- {
-
- AEDesc dWhoseRange, dRangeStart ;
- AERecord dWhoseRecord, dWhoseRangeRec ;
- IndexRecord index ;
- DescType typeCode ;
- Size actualSize ;
- OSErr err ;
-
- // DebugStr("\pOSLInit.MakeExternalWhose: Inside MakeExternalWhose. Call Nick.");
-
- err = AECoerceDesc( desc, typeAERecord, &dWhoseRecord ) ;
- if ( err != noErr ) goto a ;
-
- err = AEGetKeyPtr( &dWhoseRecord, keyAEIndex, typeWhoseRangeInternal, &typeCode,
- (Ptr)&index, sizeof(index), &actualSize ) ;
- if ( err != noErr ) goto b ;
-
- err = AECreateDesc( index.startCase, (Ptr)&index.startValue, SizeOf(index.startValue),
- &dRangeStart ) ;
- if ( err != noErr ) goto b ;
-
- if ( index.stopCase == typeNull )
- {
- dWhoseRange = dRangeStart ;
- dRangeStart.dataHandle = NULL ; /* so we don't double dispose */
- dWhoseRangeRec.dataHandle = NULL ;
- }
- else
- {
- err = AECreateList( NULL, 0, true, &dWhoseRangeRec ) ;
- if ( err != noErr ) goto c ;
-
- err = AEPutKeyPtr( &dWhoseRangeRec, keyAEWhoseRangeStop, index.stopCase,
- (Ptr)&index.stopValue, sizeof(index.stopValue) ) ;
- if ( err != noErr ) goto d ;
-
- err = AEPutKeyDesc( &dWhoseRangeRec, keyAEWhoseRangeStart, &dRangeStart ) ;
- if ( err != noErr ) goto d ;
-
- err = AECoerceDesc( &dWhoseRangeRec, typeWhoseRange, &dWhoseRange) ;
- if ( err != noErr ) goto d ;
- } ;
-
- err = AEPutKeyDesc( &dWhoseRecord, keyAEIndex, &dWhoseRange ) ;
- if ( err != noErr ) goto e ;
-
- err = AECoerceDesc( &dWhoseRecord, typeWhoseDescriptor, result ) ;
-
- e:
- IgnoreOSErr( AEDisposeDesc( &dWhoseRange ) ) ;
- d:
- IgnoreOSErr( AEDisposeDesc( &dWhoseRangeRec ) ) ;
- c:
- IgnoreOSErr( AEDisposeDesc( &dRangeStart ) ) ;
- b:
- IgnoreOSErr( AEDisposeDesc( &dWhoseRecord ) ) ;
- a:
- return err ;
- } // MakeExternalWhose
-
-
- //———————————————————————— iAESetObjectCallbacks ————————————————————————
- pascal OSErr
- iAESetObjectCallbacks( OSLCompareUPP myCompareProc, OSLCountUPP myCountProc,
- OSLDisposeTokenUPP myDisposeTokenProc,
- OSLGetMarkTokenUPP myGetMarkTokenProc, OSLMarkUPP myMarkProc,
- OSLAdjustMarksUPP myAdjustMarksProc,
- OSLGetErrDescUPP reserved )
-
- // changed model to allow nil procs; replace/enter iff non-nil
- {
- OSErr out ;
-
- out = noErr ;
-
- if ( myCompareProc != NULL )
- out = AEInstallSpecialHandler( keyAECompareProc,
- (UniversalProcPtr)myCompareProc, false ) ;
- // ELSE
- // out := errRequiredProcAbsent;
-
- if ( (out == noErr) && (myCountProc != NULL) )
- out = AEInstallSpecialHandler( keyAECountProc, (UniversalProcPtr)myCountProc, false ) ;
- // ELSE
- // out := errRequiredProcAbsent;
-
- // these procs are optional, so we are less upset about not seeing them //<eeh> added first two
- if ( (out == noErr) && (myDisposeTokenProc != NULL) )
- out = AEInstallSpecialHandler( keyDisposeTokenProc,
- (UniversalProcPtr)myDisposeTokenProc, false);
-
- if ( (out == noErr) && (myGetMarkTokenProc != NULL) )
- out = AEInstallSpecialHandler( keyAEMarkTokenProc,
- (UniversalProcPtr)myGetMarkTokenProc, false);
- if ( (out == noErr) && (myMarkProc != NULL) )
- out = AEInstallSpecialHandler(keyAEMarkProc,
- (UniversalProcPtr)myMarkProc, false);
- if ( (out == noErr) && (myAdjustMarksProc != NULL) )
- out = AEInstallSpecialHandler( keyAEAdjustMarksProc,
- (UniversalProcPtr)myAdjustMarksProc, false);
-
- if ( ( out == noErr ) && ( reserved != NULL ) )
- out = AEInstallSpecialHandler( keyAEGetErrDescProc,
- (UniversalProcPtr)reserved, false ) ;
-
- return out; // <eeh> in Pascal, this preceeded last if above
- } // iAESetObjectCallbacks
-
-
- #if 0
- // Currently this routine does nothing...
-
- #ifndef __FRAGLOAD__
- #include <FragLoad.h>
- #endif
-
- #ifndef __MACRUNTIME__
- #include <MacRuntime.h>
- #endif
-
- #pragma lib_export on
-
- pascal OSErr OSLCFMInit (InitBlockPtr initBlkPtr)
- {
- return noErr;
- }
-
- #endif /*0*/